<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="进度编号">
              <a-input placeholder="请输入进度编号" v-model="queryParam.billNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号">
              <j-input placeholder="请输入项目编号" v-model="queryParam.projectFinalNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务档案编号">
              <j-input placeholder="请输入任务档案编号" v-model="queryParam.taskBillNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目负责人">
              <j-input placeholder="请输入项目负责人" v-model="queryParam.projLeadName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="生产团队">
              <select-team-input
                v-model="queryParam.productTeam"
                :tdlx="2"
                :triggerChange="true"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="指派时间">
              <a-range-picker
                style="width: 100%"
                :show-time="{ format: 'HH:mm:ss' }"
                format="YYYY-MM-DD HH:mm:ss"
                :placeholder="['请选择开始时间', '请选择结束时间']"
                @change="onCreateTimeChange"
                v-model="CreateTimeDate"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="匹配合同额(元)">
              <a-input-number
                placeholder="请输入最小金额"
                :max="99999999"
                :min="0"
                :precision="2"
                style="width: 47%"
                @change="(val) => this.newContractAmount = Number(val)"
                v-model="queryParam.newContractAmount_begin"></a-input-number>
              -
              <a-input-number
                placeholder="请输入最大金额"
                :max="99999999"
                :min="newContractAmount"
                :precision="2"
                style="width: 47%"
                v-model="queryParam.newContractAmount_end"></a-input-number>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="进度百分比(%)">
              <a-input-number
                placeholder="请输入最小值"
                :max="100"
                :min="0"
                :precision="2"
                style="width: 47%"
                @change="(val) => this.contractRate = Number(val)"
                v-model="queryParam.contractRate_begin"></a-input-number>
              -
              <a-input-number
                placeholder="请输入最大值"
                :max="100"
                :min="contractRate"
                :precision="2"
                style="width: 47%"
                v-model="queryParam.contractRate_end"></a-input-number>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="预算工时(人天)">
              <a-input-number
                placeholder="请输入最小值"
                :max="99999999"
                :min="0"
                :precision="2"
                style="width: 47%"
                @change="(val) => this.expectTotalHours = Number(val)"
                v-model="queryParam.expectTotalHours_begin"></a-input-number>
              -
              <a-input-number
                placeholder="请输入最大值"
                :max="99999999"
                :min="expectTotalHours"
                :precision="2"
                style="width: 47%"
                v-model="queryParam.expectTotalHours_end"></a-input-number>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务进度状态">
              <j-dict-select-tag placeholder="请选择任务进度状态" v-model="queryParam.taskStatus" dictCode="progress_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="完成时间">
              <a-range-picker
                style="width: 100%"
                :show-time="{ format: 'HH:mm:ss' }"
                format="YYYY-MM-DD HH:mm:ss"
                :placeholder="['请选择开始时间', '请选择结束时间']"
                @change="onCompleteTimeChange"
                v-model="CompleteTimeDate"
              />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="projectName" :title="text" slot-scope="text, record" @click="onDetail(record.projectId)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <a slot="projectNo" slot-scope="text, record" @click="handleViews(record.projectId)">{{ text }}</a>
        <span slot="action" slot-scope="text, record">
          <!--  -->
          <!-- <a @click="handleEditTemplate(record)" v-if="record.taskStatus == 'wait_perfect'">
            完善
          </a> -->
          <!-- <a-divider type="vertical"/> -->
          <!-- v-if="record.taskStatus == 'wait_write' || record.taskStatus == 'running'" -->
          <a @click="handleEditNode(record)" v-if="record.taskStatus == 'wait_write' || record.taskStatus == 'running'">
            填报
          </a>
          <a-divider type="vertical" v-if="record.taskStatus == 'wait_write' || record.taskStatus == 'running'"/>
          <a @click="handleSee(record)">
            查看
          </a>
        </span>

      </a-table>
    </div>
    <!-- <a-tabs defaultActiveKey="1" @change="tabsChange">
      <a-tab-pane tab="所有任务" key="1">
        <erp-progress-task-list ref="erpProgressTaskList" @refresh="refreshNew"></erp-progress-task-list>
      </a-tab-pane>
      <a-tab-pane tab="分配给我" key="2" forceRender>
        <erp-progress-assigned-me-task-list ref="assignedMeTaskList" @refresh="refreshNew" ></erp-progress-assigned-me-task-list>
      </a-tab-pane>
      <a-tab-pane tab="由我分配" key="3" forceRender>
        <erp-progress-my-assigned-task-list ref="myAssignedTaskList" @refresh="refreshNew"></erp-progress-my-assigned-task-list>
      </a-tab-pane>
    </a-tabs> -->
    <!-- 完善弹窗 -->
    <erp-progress-task-modal ref="taskModal" @ok="modalFormOk"></erp-progress-task-modal>
    <erp-progress-assigned-task-modal ref="assignedModalForm" @ok="modalFormOk"></erp-progress-assigned-task-modal>
    <erp-progress-task-node-modal ref="modalForm" @ok="modalFormOk" @closeAndFetch="loadData(1)"></erp-progress-task-node-modal>
    <!-- 项目详情开始 -->
    <erp-project-report-modal ref="projectModalForm"></erp-project-report-modal>
    <!-- 项目详情结束 -->
  </a-card>
</template>
<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import ErpProgressTaskList from './ErpProgressTaskList'
  import ErpProgressAssignedMeTaskList from './ErpProgressAssignedMeTaskList'
  import ErpProgressMyAssignedTaskList from './ErpProgressMyAssignedTaskList'
  import { mapGetters } from 'vuex';
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput';
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep';
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  import { getAction } from '@/api/manage'
  import ErpProgressTaskModal from '@/views/erp/progress/modules/ErpProgressTaskModal' // 完善弹窗
  import ErpProgressTaskNodeModal from '@/views/erp/progress/modules/ErpProgressTaskNodeModal' // 填报弹窗
  import ErpProgressAssignedTaskModal from '@/views/erp/progress/modules/ErpProgressAssignedTaskModal'
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'
  export default {
    name: 'ErpProgressTaskProjectList',
    mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpProgressTaskList,
      ErpProgressAssignedMeTaskList,
      ErpProgressMyAssignedTaskList,
      SelectTeamInput,
      SelectUserByDep,
      ErpProgressAssignedTaskModal,
      ErpProgressTaskModal,
      ErpProgressTaskNodeModal,
      ErpProjectReportModal
    },
    data () {
      return {
        CreateTimeDate: [], // 指派时间
        CompleteTimeDate: [], // 完成时间
        description: '项目进度管理页面',
        // 表头
        columns: [],
        // 列设置
        settingColumns: [],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            fixed: 'left',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '进度编号',
            align: 'center',
            dataIndex: 'billNo',
            ellipsis: true,
            fixed: 'left',
            width: 175
          },
          {
            title: '项目名称',
            align: 'center',
            dataIndex: 'projectName',
            key: 'projectName',
            scopedSlots: { customRender: 'projectName' },
            ellipsis: true,
            fixed: 'left',
            width: 175
          },
          {
            title: '项目编号',
            align: 'center',
            dataIndex: 'projectFinalNo',
            ellipsis: true,
            fixed: 'left',
            width: 175
          },
          {
            title: '项目负责人',
            align: 'center',
            dataIndex: 'projLeadName',
            fixed: 'left',
            customRender: (text) => {
              if (text === '' || text === null || text === undefined) {
                return '--'
              } else {
                return text
              }
            },
            ellipsis: true,
            width: 90
          },
          {
            title: '任务档案编号',
            align: 'center',
            dataIndex: 'taskBillNo',
            fixed: 'left',
            width: 175,
            // scopedSlots: { customRender: 'taskBillNo' },
            ellipsis: true
          },
          {
            title: '生产团队',
            align: 'center',
            dataIndex: 'productTeam_dictText',
            customRender: (text) => {
              if (text === '' || text === null || text === undefined) {
                return '--'
              } else {
                return text
              }
            },
            ellipsis: true,
            width: 150
          },
          {
            title: '指派时间',
            align: 'center',
            dataIndex: 'createTime',
            customRender: (text) => {
              if (text === '' || text === null || text === undefined) {
                return '--'
              } else {
                return text
              }
            },
            ellipsis: true,
            width: 150
          },
          {
            title: '匹配合同额(元)',
            align: 'center',
            dataIndex: 'newContractAmount',
            customRender: (text) => {
              if (text === '' || text === null || text === undefined) {
                return '--'
              } else {
                return text
              }
            },
            ellipsis: true,
            width: 130
          },
          {
            title: '进度百分比(%)',
            align: 'center',
            dataIndex: 'contractRate',
            customRender: (text) => {
              if (text === '' || text === null || text === undefined) {
                return '--'
              } else {
                return text
              }
            },
            ellipsis: true,
            width: 130
          },
          {
            title: '预算工时(天)',
            align: 'center',
            dataIndex: 'expectTotalHours',
            customRender: (text) => {
              if (text === '' || text === null || text === undefined) {
                return '--'
              } else {
                var num = Number(text).toFixed(1)
                return num
              }
            },
            ellipsis: true,
            width: 130
          },
          {
            title: '任务进度状态',
            align: 'center',
            dataIndex: 'taskStatus',
            customRender: (text) => {
              if (!text) {
                return '--'
              } else {
                return filterMultiDictText(this.dictOptions['taskStatus'], text + '')
              }
            },
            ellipsis: true,
            width: 130
          },
          {
            title: '完成时间',
            align: 'center',
            dataIndex: 'completeTime',
            customRender: (text) => {
              if (!text) {
                return '--'
              } else {
                return filterMultiDictText(this.dictOptions['taskStatus'], text + '')
              }
            },
            ellipsis: true,
            width: 175
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 150,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: '/api/erp/progress/erpProgressTask/list',
          queryProjectById: '/api/erp/project/report/erpProjectReport/queryById'
        },
        dictOptions: {},
        superFieldList: [],
        isorter: {
          column: 'billNo',
          order: 'desc'
        },
        selectedRowKey: '',

        newContractAmount: 0,
        contractRate: 0,
        expectTotalHours: 0,
        consumedHours: 0
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {

    },
    methods: {
      ...mapGetters(['userInfo']),
      onSelectOne(selectedRowKeys, selectionRows) {
        this.selectedRowKey = selectedRowKeys
        this.$refs.erpProgressTaskList.refreshData(selectedRowKeys)
      },
      searchReset() {
      this.onClearSelected();
      this.queryParam = {}
      this.CreateTimeDate = [] // 指派时间
      this.CompleteTimeDate = [] // 完成时间
      this.loadData(1)
    },
      initDictConfig() {
        initDictOptions('progress_status').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'taskStatus', res.result)
          }
        })
      },
      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectById, { id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectModalForm.getDetail(model);
              that.$refs.projectModalForm.title = '项目一览表';
            }
          })
        })
      },
      getDetail(id) {
      this.$router.push({
        path: `/erp/purchase/procurement/ErpPurchaseApplyInvitationListDetail/${id}`
      })
    },
      onTaskDetail (record) {
        this.$router.push({
          path: `/taskdistribution/ErpOmcCTaskDistributionFileListDetail/${record.projectTaskId}`
        })
      },
      onCreateTimeChange (value, dateString) {
        this.queryParam.createTime_begin = dateString[0]
        this.queryParam.createTime_end = dateString[1]
      },
      onCompleteTimeChange (value, dateString) {
        this.queryParam.completeTime_begin = dateString[0]
        this.queryParam.completeTime_end = dateString[1]
      },
      handleViews(id) {
        this.$router.push({
          path: `/erp/omc/project/ErpOmcProjectListDetail/${id}`
        })
      },
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'projectStatus', text: '项目状态', dictCode: 'complete_status' })
        this.superFieldList = fieldList
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectionRows = selectionRows
      },
      refreshNew() {
        this.loadData(1)
      },
      // 点击切换事件
      tabsChange (e) {
        if (this.selectedRowKey) {
          if (e == 1) {
            this.$refs.erpProgressTaskList.refreshData(this.selectedRowKey)
          } else if (e == 2) {
            this.$refs.assignedMeTaskList.refreshData(this.selectedRowKey)
          } else if (e == 3) {
            this.$refs.myAssignedTaskList.refreshData(this.selectedRowKey)
          }
        }
      },
      // 完善页面
      handleEditTemplate: function (record) {
        this.$refs.taskModal.edit(record)
        this.$refs.taskModal.title = '完善信息'
        this.$refs.taskModal.disableSubmit = false
      },
      handleEditNode: function (record) {
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '进度填报'
        this.$refs.modalForm.disableSubmit = false
      },
      // 查看
      handleSee (record) {
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '详情'
        this.$refs.modalForm.disableSubmit = true
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
